{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ad17228f",
   "metadata": {},
   "source": [
    "### 购物车程序项目：\n",
    " \n",
    " \n",
    " * 要求：\n",
    " \n",
    "    * 1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "    \n",
    "    * 2、让用户输入商品编号进行商品的购买。\n",
    "    \n",
    "    * 3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "    \n",
    "    * 4、用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b7306148",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的余额：1114\n",
      "------goods list-------\n",
      "['10001', 'python课本', '88']\n",
      "['10002', '蜜雪冰城—冰茶', '10']\n",
      "['10003', 'iphone13 pro', '9999']\n",
      "['10004', '华为电-跑车', '400000']\n",
      "['10005', '小米手环', '199']\n",
      "\n",
      "请输入商品的ID：2\n",
      "['10001', 'python课本', '88']\n",
      "您输入的商品信息有问题，请输入正确的商品ID\n",
      "['10002', '蜜雪冰城—冰茶', '10']\n",
      "您输入的商品信息有问题，请输入正确的商品ID\n",
      "['10003', 'iphone13 pro', '9999']\n",
      "您输入的商品信息有问题，请输入正确的商品ID\n",
      "['10004', '华为电-跑车', '400000']\n",
      "您输入的商品信息有问题，请输入正确的商品ID\n",
      "['10005', '小米手环', '199']\n",
      "您输入的商品信息有问题，请输入正确的商品ID\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "goods = [\n",
    "    [\"10001\",\"python课本\",\"88\"],\n",
    "    [\"10002\",\"蜜雪冰城—冰茶\",\"10\"],\n",
    "    [\"10003\",\"iphone13 pro\",\"9999\"],\n",
    "    [\"10004\",\"华为电-跑车\",\"400000\"],\n",
    "    [\"10005\",\"小米手环\",\"199\"]\n",
    "]\n",
    "user_shop_list = []\n",
    "\n",
    "支付宝余额 = input(\"请输入您的余额：\")\n",
    "info = '''------goods list-------\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "%s\n",
    "'''%(goods[0],goods[1],goods[2],goods[3],goods[4])\n",
    "print(info)\n",
    "user_input_ID = input(\"请输入商品的ID：\")\n",
    "for good in goods:\n",
    "    print(good)\n",
    "  \n",
    "    if user_input_ID == good[0]:                 # 判断商品的id是否正确\n",
    "        \n",
    "        if int(good[2]) < int(支付宝余额):       # 判断用户的余额是否够用\n",
    "           \n",
    "            user_shop_list.append(good)           # 把商品加进list\n",
    "           \n",
    "            break                              \n",
    "\n",
    "    else:\n",
    "        print(\"您输入的商品信息有问题，请输入正确的商品ID\")\n",
    "\n",
    "print(user_shop_list)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
